package cn.iocoder.yudao.module.alipay.controller.app.eLong;


import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.alipay.dal.dataobject.elong.common.JsonResult;
import cn.iocoder.yudao.module.alipay.dal.dataobject.elong.common.PagerDateResult;
import cn.iocoder.yudao.module.alipay.dal.dataobject.elong.hotel.HotelDetailForListPager;
import cn.iocoder.yudao.module.alipay.dal.dataobject.elong.hotel.HotelDetailRequest;
import cn.iocoder.yudao.module.alipay.dal.dataobject.elong.hotel.HotelDetailViewModel;
import cn.iocoder.yudao.module.alipay.dal.dataobject.elong.hotel.ListPagerRequest;
import cn.iocoder.yudao.module.alipay.dal.dataobject.elong.order.CreateOrderRequest;
import cn.iocoder.yudao.module.alipay.dal.dataobject.elong.pay.PaySubmitRequest;
import cn.iocoder.yudao.module.alipay.service.elong.ElongHotalService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@Tag(name = "艺龙 - 酒店相关")
@RestController
@RequestMapping("/elong/hotel/")
@Validated
public class ElongHotalController {

    @Resource
    private ElongHotalService elongHotalService;


    @GetMapping("/getHotelList")
    @Operation(summary = "获取酒店列表")
    public JsonResult<PagerDateResult<HotelDetailForListPager>> getHotelList(ListPagerRequest pagerReq, HttpServletRequest request){
        return elongHotalService.getHotelList(pagerReq,request);
    }

    @GetMapping("/getHotelDetail")
    @Operation(summary = "获取酒店详情")
    public CommonResult<HotelDetailViewModel> getHotelDetail(HotelDetailRequest detailReq, HttpServletRequest request, HttpServletResponse response){
        return CommonResult.success(elongHotalService.getHotelDetail(detailReq,request,response));
    }

    /***********************************************end 订单详情 end***********************************************/
    /***********************************************start 创建订单页 start***********************************************/
    /**
     *
     * 生成订单页面
     * 注意：页面初始化首先得判断库存
     *
     * @param request
     * @param response
     * @return
     */
    @PostMapping("/createdOrder")
    @Operation(summary = "创建订单并校验")
    public CommonResult<Map<String,Object>> createdOrder(CreateOrderRequest orderRequest, HttpServletRequest request, HttpServletResponse response){
        return CommonResult.success(elongHotalService.createdOrder(orderRequest,request,response));
    }

    /**
     *
     * 提交订单
     * 注意：
     * 1.把下单流程分为两步：1）创建订单；2)支付；此处只负责创建订单，即完成第一步。
     * 2.可以把hotel.order.create接口返回的PaymentDeadlineTime（最晚取消时间）参数传递到支付页面，来提醒用户支付时间限制；
     *
     * @param request
     * @return
     */
    @PostMapping("/submitOrder")
    @Operation(summary = "提交订单")
    public JsonResult<Boolean> submitOrder(PaySubmitRequest paySubmitReq, HttpServletRequest request){
        return elongHotalService.submitOrder(paySubmitReq,request);
    }


}





